//获取proid渲染页面

var url = location.search;
console.log(url);

var proid = url.split("=")[1];
console.log(proid);

//渲染商品
$.ajax({
    url: "./api/goods.php",
    dataType: "json",
    data: {
        proid:proid
    },
    success: function (data) {

        var text = $("#ejs-html").html();
        var html = ejs.render(text, {
            item: data
        })
        $(".xx-k").html(html);
        swiper()
        downtime()
       var title=data[0]["title"]
       var imgurl= data[0]["img_url"]
       var price= data[0]["price"]
  
        //加入购物车
           $(".addcar").click(function(data){
             
            var quantity=1;
             quantity = Number($("#quantity").text()) 
              $.ajax({
                url: "./api/addcar.php",
                dataType: "json",
                data: {
                    title:title,
                    img_url:imgurl,
                    price: price,
                    quantity:quantity
                },
                success: function (data) {
                    console.log(data);
                    
                    $(".ncar").text(data)

                }
             })
          })

    }
})

 //渲染更多商品：
var n=0;
$.ajax({
    url: "./api/goodmove.php",
    dataType: "json",
    data: {
        n:++n
    },
    success: function (data) {
     
      
        html2="";
        for(var i=0 ; i<data.length;i++){
            html2  +=` <li>
            <a href="">
                <img src="${data[i]["img_url"]}" alt="">
                <p class="t-name">${data[i]["title"]}</p>
                <p class="t-price">￥${data[i]["price"]}</p>
            </a>
        </li>`
        }
        $(".tuijian ul").html(html2)
    }
})



//top关闭按钮变化
$(".right").on("click",function(){
    $(".gd").fadeToggle(200);
    $(".gb").fadeToggle(200);
})

//top隐藏栏关闭
$(".gb").on("click",function(){
   $(".top-hidden").css({
       height:".0rem",
       borderBottom: ".0rem"
   })
})
//top隐藏栏打开 gd更多
$(".gd").on("click",function(){
    $(".top-hidden").css({
        height:".6rem",
        borderBottom: ".02rem solid #fe8477"
    })
})

//top下划线
$(".top-cont li").on("click",function(){
    $(this).addClass("xhx").siblings().removeClass("xhx")
})

//swiper轮播
function swiper(){
    var mySwiper = new Swiper ('#banner', {
        loop: true, 
        pagination: {
          el: '.swiper-pagination',
        }
      })  
}
  
  
//闪购倒计时
function downtime(){
    var time =$(".time")
    setInterval(function(){
        var d3=new Date("2019/11/11 11:11:11")-new Date(); 
        var tian=Math.floor(d3/1000/60/60/24) 
        var shi=Math.floor((d3/1000/60/60)%24) 
        var fen=Math.floor((d3/1000/60)%60)
        var miao=Math.floor((d3/1000)%60)
        if(shi<10){
            shi="0"+shi
        }
       if(fen<10){
           fen="0"+fen
       } 
        if(miao<10){
            miao="0"+miao
        }
        html=`${tian}天 ${shi}:${fen}:${miao}`
        time.html(html)
    },1000)
}


//地址三级联动：

var di = new Swiper ('#di', {
    direction: 'vertical', // 垂直切换选项
    slidesPerView: 'auto',//设置slider容器能够同时显示的slides数量

  })        
  var di = new Swiper ('#shi', {
    direction: 'vertical', // 垂直切换选项
    freeMode:true,

  })   
  var di = new Swiper ('#qu', {
    direction: 'vertical', // 垂直切换选项
    freeMode:true,
  })   


//top栏弹出效果：
$(window).scroll(function(){
    var top=$(window).scrollTop()//当前窗口偏移量
    $(".top ul").css({
        opacity:top/300
    })
})




